{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 百度AI-通用物体和场景识别"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 获取token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.742a3d2073ef3c4eab55205401378c56.315360000.1910313835.282335-21426912', 'expires_in': 2592000, 'session_key': '9mzdWu6CwoQY/QuS2DJLEvxoQaFeHCqLXm/Xyfw1VXgCvqsLKbM4z2EdL5DRC5cZ2qK5qlNaroEcEIH4iqhEFVcHWk7pQw==', 'access_token': '24.a2cdb1ffaf9e40423d4353e0201f9d39.2592000.1597545835.282335-21426912', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理', 'session_secret': '4cef4f9cb253d9b8f1c1e1e24f44b4f3'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=3m4xymWPlGjL4fPkPzVM1XTC&client_secret=cNghqBuPgViKxKOUNfQy2PdE5WZj5xY0'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 场景识别（广州塔)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 6645408401146862865, 'result_num': 5, 'result': [{'score': 0.939497, 'root': '', 'keyword': '广州塔'}, {'score': 0.740229, 'root': '建筑-建筑夜景', 'keyword': '都市夜景'}, {'score': 0.563698, 'root': '', 'keyword': '珠江夜游'}, {'score': 0.356865, 'root': '建筑-现代建筑', 'keyword': '建筑'}, {'score': 0.114033, 'root': '建筑-建筑夜景', 'keyword': '夜景照明'}]}\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "from PIL import Image\n",
    "import base64\n",
    "\n",
    "\n",
    "'''\n",
    "通用物体和场景识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('guanzhouta.jpg','rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\n",
    "    \"image\":img,\n",
    "    \"baike_num\":\"plantnum\"\n",
    "         }\n",
    "access_token = '24.a2cdb1ffaf9e40423d4353e0201f9d39.2592000.1597545835.282335-21426912'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>log_id</th>\n",
       "      <th>result_num</th>\n",
       "      <th>result</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6645408401146862865</td>\n",
       "      <td>5</td>\n",
       "      <td>[{'score': 0.939497, 'root': '', 'keyword': '广...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                log_id  result_num  \\\n",
       "0  6645408401146862865           5   \n",
       "\n",
       "                                              result  \n",
       "0  [{'score': 0.939497, 'root': '', 'keyword': '广...  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.json_normalize(response.json())\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 物体识别（汗血马）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "名称: 汗血马\n",
      "可能性: 0.887546\n",
      "百科描述: 汗血宝马，学名阿哈尔捷金马(英文名：Akhal-teke horses)，原产于土库曼斯坦。头细颈高，四肢修长，皮薄毛细，步伐轻盈，力量大、速度快、耐力强。德、俄、英等国的名马大都有阿哈尔捷金马的血统。汗血宝马是土库曼斯坦的国宝，并将其形象绘制在国徽和货币上。(概述图参考来源：)\n",
      "百科链接: http://baike.baidu.com/item/%E6%B1%97%E8%A1%80%E5%AE%9D%E9%A9%AC/14310\n",
      "百科图片: https://bkimg.cdn.bcebos.com/pic/5fdf8db1cb13495409235a1d56078558d109b3dedc3b\n"
     ]
    }
   ],
   "source": [
    "#通用物体与场景识别，返回可能性最大的通用物体与场景 \n",
    "#filename:图片名（本地存储包括路径）,plantnum展示的数量\n",
    "def general(filename,plantnum):\n",
    "    request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general\" \n",
    "    # 二进制方式打开图片文件 \n",
    "    f = open('hanxuema.jpg', 'rb') \n",
    "    img = base64.b64encode(f.read()) \n",
    "    params = dict()\n",
    "    params['image'] = img \n",
    "    params['baike_num'] = plantnum \n",
    "    params = urllib.parse.urlencode(params).encode(\"utf-8\") \n",
    "    #params = json.dumps(params).encode('utf-8') \n",
    "    access_token = '24.a2cdb1ffaf9e40423d4353e0201f9d39.2592000.1597545835.282335-21426912'\n",
    "    request_url = request_url + \"?access_token=\" + access_token\n",
    "    request = urllib.request.Request(url=request_url, data=params)\n",
    "    request.add_header('Content-Type', 'application/x-www-form-urlencoded')\n",
    "    response = urllib.request.urlopen(request) \n",
    "    content = response.read() \n",
    "    if content: \n",
    "        #print(content)\n",
    "        content=content.decode('utf-8') \n",
    "        #print(content) \n",
    "        data = json.loads(content)\n",
    "        result=data['result']\n",
    "        nums=min(plantnum,len(result))\n",
    "        for i in range(0,nums):\n",
    "            item=result[i]\n",
    "            print ('名称:',item['keyword'])\n",
    "            print ('可能性:',item['score'])\n",
    "            baike_info=item['baike_info']\n",
    "            print ('百科描述:',baike_info['description'])\n",
    "            print ('百科链接:',baike_info['baike_url']) \n",
    "            print ('百科图片:',baike_info['image_url'])\n",
    "general(\"汗血马.jpg\",1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 高德地图-路径规划api"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>formatted_address</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>citycode</th>\n",
       "      <th>city</th>\n",
       "      <th>district</th>\n",
       "      <th>township</th>\n",
       "      <th>adcode</th>\n",
       "      <th>street</th>\n",
       "      <th>number</th>\n",
       "      <th>location</th>\n",
       "      <th>level</th>\n",
       "      <th>neighborhood.name</th>\n",
       "      <th>neighborhood.type</th>\n",
       "      <th>building.name</th>\n",
       "      <th>building.type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广东省中山市振兴路|22号</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东省</td>\n",
       "      <td>0760</td>\n",
       "      <td>中山市</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>442000</td>\n",
       "      <td>振兴路</td>\n",
       "      <td>22号</td>\n",
       "      <td>113.182740,22.663524</td>\n",
       "      <td>门牌号</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  formatted_address country province citycode city district township  adcode  \\\n",
       "0     广东省中山市振兴路|22号      中国      广东省     0760  中山市       []       []  442000   \n",
       "\n",
       "  street number              location level neighborhood.name  \\\n",
       "0    振兴路    22号  113.182740,22.663524   门牌号                []   \n",
       "\n",
       "  neighborhood.type building.name building.type  \n",
       "0                []            []            []  "
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 前期准备（获取地理编码）\n",
    "def geocode(address:str,city=None,batch=None,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/geocode/geo?parameters'\n",
    "    params = {\n",
    "        'key':\"f01e5675ced7f03e2a139d402e372ad8\",\n",
    "        'address':\"广东省中山市古镇镇海洲红庙振兴路22号\",\n",
    "        'city':\"中山\",\n",
    "        'batch':True,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "家 = geocode('广东省中山市古镇镇海洲红庙振兴路22号')\n",
    "家\n",
    "df = pd.json_normalize(家['geocodes'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>formatted_address</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>citycode</th>\n",
       "      <th>city</th>\n",
       "      <th>district</th>\n",
       "      <th>township</th>\n",
       "      <th>adcode</th>\n",
       "      <th>street</th>\n",
       "      <th>number</th>\n",
       "      <th>location</th>\n",
       "      <th>level</th>\n",
       "      <th>neighborhood.name</th>\n",
       "      <th>neighborhood.type</th>\n",
       "      <th>building.name</th>\n",
       "      <th>building.type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广东省中山市海洲初级中学</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东省</td>\n",
       "      <td>0760</td>\n",
       "      <td>中山市</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>442000</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.172547,22.653820</td>\n",
       "      <td>兴趣点</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  formatted_address country province citycode city district township  adcode  \\\n",
       "0      广东省中山市海洲初级中学      中国      广东省     0760  中山市       []       []  442000   \n",
       "\n",
       "  street number              location level neighborhood.name  \\\n",
       "0     []     []  113.172547,22.653820   兴趣点                []   \n",
       "\n",
       "  neighborhood.type building.name building.type  \n",
       "0                []            []            []  "
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 前期准备（获取地理编码）\n",
    "def geocode(address:str,city=None,batch=None,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/geocode/geo?parameters'\n",
    "    params = {\n",
    "        'key':\"f01e5675ced7f03e2a139d402e372ad8\",\n",
    "        'address':\"广东省中山市古镇海洲初级中学\",\n",
    "        'city':\"中山\",\n",
    "        'batch':True,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "海中 = geocode('广东省中山市古镇海洲初级中学')\n",
    "海中\n",
    "df = pd.json_normalize(海中['geocodes'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 规划路线\n",
    "# 准备base_url，params，response。json（）113.181066,22.658546\n",
    "def walking(origin,destination,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/direction/walking?parameters'\n",
    "    params={\n",
    "        'key':\"f01e5675ced7f03e2a139d402e372ad8\",\n",
    "        'origin':origin,\n",
    "        'destination':destination,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(起点)家_location: 113.182740,22.663524 (终点)海中_location: 113.172547,22.653820\n"
     ]
    }
   ],
   "source": [
    "# 准备walking参数\n",
    "# B-2 准备walking 参数\n",
    "海中 = geocode('广东省中山市古镇海洲初级中学')\n",
    "#print(目的地)\n",
    "海中_location = 海中['geocodes'][0]['location']\n",
    "#print(目的地_location)\n",
    "家_location = 家['geocodes'][0]['location']\n",
    "#print(家_location)\n",
    "print(\"(起点)家_location:\",家_location,\"(终点)海中_location:\",海中_location)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>orientation</th>\n",
       "      <th>road</th>\n",
       "      <th>distance</th>\n",
       "      <th>duration</th>\n",
       "      <th>polyline</th>\n",
       "      <th>action</th>\n",
       "      <th>assistant_action</th>\n",
       "      <th>walk_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>向西南步行113米向左前方行走</td>\n",
       "      <td>西南</td>\n",
       "      <td>[]</td>\n",
       "      <td>113</td>\n",
       "      <td>90</td>\n",
       "      <td>113.182912,22.66329;113.182361,22.662943;113.1...</td>\n",
       "      <td>向左前方行走</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>向东南步行96米右转</td>\n",
       "      <td>东南</td>\n",
       "      <td>[]</td>\n",
       "      <td>96</td>\n",
       "      <td>77</td>\n",
       "      <td>113.182036,22.662678;113.182036,22.662648;113....</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>沿海兴路向西南步行1243米左转</td>\n",
       "      <td>西南</td>\n",
       "      <td>海兴路</td>\n",
       "      <td>1243</td>\n",
       "      <td>994</td>\n",
       "      <td>113.182491,22.661936;113.182231,22.661766;113....</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沿西岸北路向东南步行139米向右前方行走</td>\n",
       "      <td>东南</td>\n",
       "      <td>西岸北路</td>\n",
       "      <td>139</td>\n",
       "      <td>111</td>\n",
       "      <td>113.17224,22.655829;113.172543,22.655291;113.1...</td>\n",
       "      <td>向右前方行走</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>向南步行157米右转</td>\n",
       "      <td>南</td>\n",
       "      <td>[]</td>\n",
       "      <td>157</td>\n",
       "      <td>126</td>\n",
       "      <td>113.172986,22.654787;113.173125,22.654375;113....</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>向西北步行64米到达目的地</td>\n",
       "      <td>西北</td>\n",
       "      <td>[]</td>\n",
       "      <td>64</td>\n",
       "      <td>51</td>\n",
       "      <td>113.173008,22.653533;113.172908,22.653741;113....</td>\n",
       "      <td>[]</td>\n",
       "      <td>到达目的地</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            instruction orientation  road distance duration  \\\n",
       "0       向西南步行113米向左前方行走          西南    []      113       90   \n",
       "1            向东南步行96米右转          东南    []       96       77   \n",
       "2      沿海兴路向西南步行1243米左转          西南   海兴路     1243      994   \n",
       "3  沿西岸北路向东南步行139米向右前方行走          东南  西岸北路      139      111   \n",
       "4            向南步行157米右转           南    []      157      126   \n",
       "5         向西北步行64米到达目的地          西北    []       64       51   \n",
       "\n",
       "                                            polyline  action assistant_action  \\\n",
       "0  113.182912,22.66329;113.182361,22.662943;113.1...  向左前方行走               []   \n",
       "1  113.182036,22.662678;113.182036,22.662648;113....      右转               []   \n",
       "2  113.182491,22.661936;113.182231,22.661766;113....      左转               []   \n",
       "3  113.17224,22.655829;113.172543,22.655291;113.1...  向右前方行走               []   \n",
       "4  113.172986,22.654787;113.173125,22.654375;113....      右转               []   \n",
       "5  113.173008,22.653533;113.172908,22.653741;113....      []            到达目的地   \n",
       "\n",
       "  walk_type  \n",
       "0         0  \n",
       "1         0  \n",
       "2         0  \n",
       "3         0  \n",
       "4         0  \n",
       "5         0  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "0         向西南步行113米向左前方行走\n",
       "1              向东南步行96米右转\n",
       "2        沿海兴路向西南步行1243米左转\n",
       "3    沿西岸北路向东南步行139米向右前方行走\n",
       "4              向南步行157米右转\n",
       "5           向西北步行64米到达目的地\n",
       "Name: instruction, dtype: object"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 路径规划\n",
    "家_海中 = walking(家_location,海中_location)\n",
    "df_步行路径规划 = pd.json_normalize(家_海中[\"route\"][\"paths\"][0]['steps'])\n",
    "display(df_步行路径规划)\n",
    "df_步行路径规划[\"instruction\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(起点)家_location: 113.172547,22.653820 (终点)海中_location: 113.172547,22.653820\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>status</th>\n",
       "      <th>info</th>\n",
       "      <th>infocode</th>\n",
       "      <th>count</th>\n",
       "      <th>route.origin</th>\n",
       "      <th>route.destination</th>\n",
       "      <th>route.paths</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>ok</td>\n",
       "      <td>10000</td>\n",
       "      <td>1</td>\n",
       "      <td>113.172547,22.653820</td>\n",
       "      <td>113.172547,22.653820</td>\n",
       "      <td>[{'distance': '1', 'duration': '1', 'steps': [...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  status info infocode count          route.origin     route.destination  \\\n",
       "0      1   ok    10000     1  113.172547,22.653820  113.172547,22.653820   \n",
       "\n",
       "                                         route.paths  \n",
       "0  [{'distance': '1', 'duration': '1', 'steps': [...  "
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def integrated(origin,destination,city,cityd=None,extensions='base',strategy=None,nightflag=0,date=None,time=None,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/direction/walking?parameters'\n",
    "    params={\n",
    "        'key':\"f01e5675ced7f03e2a139d402e372ad8\",\n",
    "        'origin':origin,\n",
    "        'destination':destination,\n",
    "        'city':city,\n",
    "        'cityd':cityd,\n",
    "        'extensions':extensions,\n",
    "        'strategy':strategy,\n",
    "        'nightflag':nightflag,\n",
    "        'date':date,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "\n",
    "# 准备乘车的参数\n",
    "家 = geocode('广东省中山市古镇镇海洲红庙振兴路22号')\n",
    "家_location = 家['geocodes'][0]['location']\n",
    "海中 = geocode('广东省中山市古镇海洲初级中学')\n",
    "海中_location = 海中['geocodes'][0]['location']\n",
    "print(\"(起点)家_location:\",家_location,\"(终点)海中_location:\",海中_location)\n",
    "\n",
    "家_海中 = integrated(家_location,海中_location,city='中山',extensions='all')\n",
    "df_bus = pd.json_normalize(家_海中)\n",
    "df_bus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
